<template lang="html">
    <div class="box">
          <div class="header">
                <el-tabs v-model="activeName" @tab-click="switchTabBar()">
                  <el-tab-pane label="推荐维修厂" name="1"></el-tab-pane>
                  <el-tab-pane label="推荐运营商" name="2"></el-tab-pane>
                </el-tabs>
          </div>

          <div class="body">
                <el-form class="filterCondition demo-form-inline" ref="form"  :inline="true" label-width="80px">
                    <el-input placeholder="推荐者名称/被推荐者名称" v-model="keyword" style="width: 420px;">
                      <el-button slot="append" style="width: 120px;" @click="switchTab()">搜索</el-button>
                    </el-input>
                    <el-form-item label="时间段" style="margin-bottom: 0;width: 520px;">
                      <el-date-picker v-model="intervalTime" type="daterange" align="right" unlink-panels range-separator="-"
                        start-placeholder="开始日期" end-placeholder="结束日期" style="width: 100%;"
                        value-format="yyyy-MM-dd HH:mm:ss" >
                      </el-date-picker>
                    </el-form-item>
                </el-form>
                <!--  -->
                <div class="table_box">
                    <el-table :data="tableData.list" style="width: 100%">
                        <el-table-column  prop="share_name"  align="center" label="推荐者" >
                          <!-- <template lang="html" slot-scope="scope">
                              <el-popover trigger="hover" placement="top">
                                  <p>姓名: {{ scope.row.share_name }}</p>
                                  <div slot="reference" class="name-wrapper">
                                    <el-tag size="medium">{{ scope.row.share_name }}</el-tag>
                                  </div>
                              </el-popover>
                          </template> -->
                        </el-table-column>
                        <el-table-column  align="center" label="被推荐者" >
                            <template slot-scope="scope">
                                <p v-for="item,index in scope.row.reg_name" :key="index">
                                    <el-popover trigger="hover" placement="top">
                                        <p>名称: {{item}}</p>
                                        <div slot="reference" class="name-wrapper">
                                          <el-tag size="medium">{{item}}</el-tag>
                                        </div>
                                    </el-popover>
                                </p>
                            </template>
                        </el-table-column>
                        <el-table-column  prop="refund_price"  align="center" label="奖励金额" ></el-table-column>
                        <el-table-column  prop="create_time"  align="center" label="时间" ></el-table-column>
                    </el-table>
                </div>


                <p  class="summary">{{tableData.total}}</p>
                <!--  -->
                <div class="page_box">
                    <el-pagination class="page" layout="prev, pager, next"
                    :current-page="currentPage"
                      @current-change="switchPage" :page-count='tableData.rows' >
                    </el-pagination>
                </div>
          </div>

    </div>
</template>

<script>
export default {
  data() {
      return {
        token: this.$store.state.user.token3,
        activeName: '1',
        currentActive:'1',
        keyword: '',
        tableData: [],
        currentPage:1,
        intervalTime: [],
      }
  },
  created(){
    this.switchTab()
  },
  methods: {
      initSetData(){
        this.keyword = ''
        this.tableData = []
        this.intervalTime = []
      },
      switchTabBar(){
          if(this.activeName == this.currentActive){
            return false;
          }else{
             this.initSetData()
             this.switchTab()
             this.currentActive = this.activeName
          }
      },
      switchTab(n=this.activeName,p=1){
        var jsonData = {
          token: this.token,
          key: this.keyword,
          start_time: (this.intervalTime && this.intervalTime[0]) || '',
          end_time: (this.intervalTime && this.intervalTime[1]) || '',
          page: p
        }
        this.currentPage = p;
        switch (n) {
          case '1': //推荐维修厂
            this.$http3.shopRecomList(jsonData)
            .then(this.resultFn(n))
            break;
          case '2':    //推荐运营商
            this.$http3.shopRecomList(jsonData)
            .then(this.resultFn(n))
            break;
        }

      },
      resultFn(n){
        return function(res) {
            this.tableData.list = []
            if(res.data.code == 1){
                for(var i=0;i<res.data.data.list.length;i++){
                  if(res.data.data.list[i].type == n){
                    this.tableData.list.push(res.data.data.list[i])
                  }
                }
                this.tableData.rows = res.data.data.rows;
                this.tableData.total = res.data.data.total;
            }
            this.$forceUpdate()
        }.bind(this)
      },

      switchPage(e){
          this.switchTab(this.activeName,e)
      }
  }
}
</script>

<style lang="css" scoped>
@import "../../../../my-style/app.css";
/deep/ .el-input-group__append, .el-input-group__prepend{
  background-color: #3498E9;
  border: none;
  color: white;
}
.page_box{
  text-align: center;
}
</style>
